# -*- coding: utf-8 -*-
import os

if __name__ == "__main__":
    fn = []

    dir = os.listdir("./log")
    for d in dir:
        if d.startswith("op"):
            fn.append(d)

    if not os.path.exists("./log/split"):
        os.makedirs("./log/split")

    for file in fn:
        # {
        #    "op1": []
        # }
        ret = {}

        with open("./log/%s" % file, 'r') as f:
            for row in f:
                cont = row.strip()
                d = cont.split(",")

                sn = d[5]

                if sn not in ret:
                    ret[sn] = []

                wsn_data = ret[sn]

                wsn_data.append(row)

        for sn in ret:
            with open("./log/split/%s" % sn, 'a') as f:
                for d in ret[sn]:
                    f.write(d)
